package client

import (
	"context"
	"fmt"
	"github.com/2103A/message/user"
	"github.com/zeromicro/go-zero/zrpc"
)

func client() user.UserClient {
	conn := zrpc.MustNewClient(zrpc.RpcClientConf{
		Target: "dns:///127.0.0.1:8183",
	})
	return user.NewUserClient(conn.Conn())
}

func UserRegister(ctx context.Context, request *user.UserRegisterRequest) (*user.UserRegisterResponse, error) {
	return client().UserRegister(ctx, request)
}

func CreateUserStarGood(ctx context.Context, userID, goodSkuID int64) (*user.UserStartGood, error) {
	info, err := client().CreateUserStarGood(ctx, &user.CreateUserStarGoodRequest{
		Info: &user.UserStartGood{
			GoodSKUID: goodSkuID,
			UserID:    userID,
		},
	})
	if err != nil {
		return nil, err
	}
	if info == nil {
		return nil, fmt.Errorf("数据不存在")
	}
	return info.Info, nil
}
